<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }

      .box {
        display: inline-block;
        margin: 100px;
      }

      .hd li {
        display: inline-block;
        width: 60px;
        text-align: center;
        cursor: pointer;
      }

      .hd .current {
        background: pink;
      }

      .bd {
        margin-top: 30px;
      }

      .bd > div {
        display: none;
        font-size: 18px;
        font-weight: bold;
      }
    </style>
    <script src="https://lib.baomitu.com/jquery/3.6.0/jquery.js"></script>
  </head>

  <body>
    <div class="box">
      <div class="hd">
        <ul>
          <li class="current">1</li>
          <li>2</li>
          <li>3</li>
          <li>4</li>
        </ul>
      </div>
      <div class="bd">
        <div style="display: block">1</div>
        <div>2</div>
        <div>3</div>
        <div>4</div>
      </div>
    </div>

    <script>
      /* let tabs = document.querySelector('.hd').querySelectorAll('li');
        let contents = document.querySelector('.bd').querySelectorAll('div');
        for (let i = 0; i < tabs.length; i++) {
            tabs[i].onclick = function() {
                for (let j = 0; j < tabs.length; j++) {
                    tabs[j].removeAttribute("class");
                    contents[j].removeAttribute("style");
                }
                this.className = "current";
                contents[i].style.display = "block";
            }
        } */
      $(".hd li").click(function () {
        $(this).addClass("current").siblings().removeClass("current");
        $(".bd").children().eq($(this).index()).show().siblings().hide();
      });
    </script>
  </body>
</html>
